<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="icon" type="image/png" sizes="16x16" href="../image/favicon.png">
    <link href="/layui/css/layui.css" rel="stylesheet">
    <title>Document</title>
</head>
<body>
    <div style="margin: 15% 40%;">
        <div style="margin: 10% 10%;position: relative;left: 30%">
            <h1>欢迎登录！</h1>
        </div>
        <form class="layui-form" >
            <!-- <div class="layui-form-item"> -->
                    <!-- <h1>欢迎登录！</h1> -->
            <!-- </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label">用户名: </label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" placeholder="请输入用户名" name="username" required>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码: </label>
                <div class="layui-input-block">
                    <input class="layui-input" type="password" placeholder="请输入密码" name="password" required >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="demo1" lay-submit>登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>    
    <script src="/layui/layui.js" type="text/javascript"></script>
    <script src="/js/shell/axios.min.js"></script>
    <script>
        layui.use(['form','layer'],function(){
            var form = layui.form;
            form.on('submit(demo1)', function(data){
                axios.
                    post('d/login',JSON.stringify(data.field))
                    .then(function(response){
                        let msg = response.data.msg;
                        layer.alert(msg);
                    });
                // layer.alert(JSON.stringify(data.field));
                // console.log(JSON.stringify(data.field)); //当前容器的全部表单字段，名值对形式：{name: value}
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</body>
</html>